package com.woniu.elderly.operation.controller;

import com.woniu.common.dto.OpenoticeDto;
import com.woniu.common.entity.*;
import com.woniu.elderly.operation.service.OpecommentService;
import com.woniu.elderly.operation.service.OpenoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

@RefreshScope
@Slf4j
@RestController
@RequestMapping("/comment")
public class OpecommentController {
    @Autowired
    OpecommentService opecommentService;

    //添加评论
    @PostMapping("/addComment/{nid}")
    public ResponseResult addComment(
            @PathVariable("nid") long nid,
            @RequestBody Opecomment opecomment){
        opecomment.setNid(nid);
        opecommentService.addComment(opecomment);
        return ResponseResult.ok("评论成功");
    }

    //获取文章的所有评论
    @GetMapping("/{nid}")
    public ResponseResult<List<Opecomment>> selectCommentsByNId(@PathVariable("nid") Long nid) {
        List<Opecomment> comments = opecommentService.selectCommentsByNId(nid);
        return ResponseResult.ok(comments);
    }



}
